/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package koor.action.teacher;

import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import koor.action.Action;
import koor.action.ActionResult;
import koor.entity.Teacher;
import koor.persistent.TeacherDAO;
import koor.service.ServiceLocator;

/**
 * The
 * <code>TeacherSearchAction</code> class represents action, used to search
 * teachers
 *
 * @author Admin
 */
public class TeacherSearchAction implements Action {

    @Override
    public String getName() {
        return "teacher.search";
    }

    @Override
    public ActionResult execute(HttpServletRequest request, HttpServletResponse response) {
        List<Teacher> teacherList;
        try {
            teacherList = ServiceLocator.getService(TeacherDAO.class).findByName(request.getParameter("name"));
        } catch (RuntimeException e) {
            teacherList = new ArrayList<Teacher>();
        }

        request.setAttribute("teacherList", teacherList);
        return ActionResult.forward("search/teacherSearch.jsp");
    }
}
